package com.julang.check.utils;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
/**
 * @author 赵自强
 * */
@ApiModel(value = "Result", description = "网络请求标准响应格式")
@Data
public class Result<T> {
    @ApiModelProperty(value = "返回码",example = CommonData.SUCCESS + "")
    private int code = 200;
    @ApiModelProperty(value = "相关操作是否成功")
    private boolean result = true;
    @ApiModelProperty(value = "提示信息")
    private String message = "";
    @ApiModelProperty(value = "响应的数据")
    private T data;

    public Result(boolean result, String message) {
        this.result = result;
        this.message = message;
    }

    public Result() {
        this.result = false;
    }

    public static<T> Result<T> buildError(int errorCode, String message, T data) {
        Result<T> result = new Result<T>();
        return result.fail(errorCode, message, data);
    }
    public static<T> Result<T> buildError(String message, T data) {
        return buildError(CommonData.FAIL, message, data);
    }
    public static<T> Result<T> buildSuccess(String message, T data) {
        Result<T> result = new Result<T>();
        return result.success(message,  data);
    }
    public static<T> Result<T> buildSuccess(T data) {
        return buildSuccess(MessageInfo.SUCCESSINFO,data);
    }
    public static Result<String> buildSuccess() {
        return buildSuccess(MessageInfo.SUCCESSINFO,"");
    }
    public Result<T> success(String message, T data) {
        this.result = true;
        this.code = CommonData.SUCCESS;
        this.message = message;
        this.data = data;
        return this;
    }

    public Result<T> fail(int errorCode, String message, T data) {
        this.result = false;
        this.code = errorCode;
        this.message = message;
        this.data = data;
        return this;
    }

    public Result(boolean result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    public static void main(String[] args) {
        System.out.println("DateFormatter".toUpperCase());
        System.out.println("FileErrorInfo".toUpperCase());
        System.out.println("UploadFileSuccessInfo".toUpperCase());
        System.out.println("FileNotExist".toUpperCase());
        System.out.println("FileNotAnalysis".toUpperCase());
        System.out.println("FileHaveExist".toUpperCase());
        System.out.println("FileException".toUpperCase());
        System.out.println("MysqlError".toUpperCase());
        System.out.println("HtmlAnalysisError".toUpperCase());
        System.out.println("SuccessInfo".toUpperCase());
        System.out.println("HtmlReportRecordNoExist".toUpperCase());
        System.out.println("RepeatWordNotExist".toUpperCase());
        System.out.println("OrderNotExist".toUpperCase());
        System.out.println("BlankPostParam".toUpperCase());
        System.out.println("UserNotExist".toUpperCase());
        System.out.println("JiFenNotEnough".toUpperCase());
        System.out.println("JiFenCalculateError".toUpperCase());
        System.out.println("OldPwdNotRight".toUpperCase());
    }
}
